home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / ASM-ARM / ARCH-ARC / IO.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  6KB  |  217 lines

  1. /*
  2.  * linux/include/asm-arm/arch-arc/io.h
  3.  *
  4.  * Copyright (C) 1997 Russell King
  5.  *
  6.  * Modifications:
  7.  *  06-Dec-1997    RMK    Created.
  8.  */
  9. #ifndef __ASM_ARM_ARCH_IO_H
  10. #define __ASM_ARM_ARCH_IO_H
  11.  
  12. /*
  13.  * This architecture does not require any delayed IO, and
  14.  * has the constant-optimised IO
  15.  */
  16. #undef    ARCH_IO_DELAY
  17.  
  18. /*
  19.  * We use two different types of addressing - PC style addresses, and ARM
  20.  * addresses.  PC style accesses the PC hardware with the normal PC IO
  21.  * addresses, eg 0x3f8 for serial#1.  ARM addresses are 0x80000000+
  22.  * and are translated to the start of IO.  Note that all addresses are
  23.  * shifted left!
  24.  */
  25. #define __PORT_PCIO(x)    (!((x) & 0x80000000))
  26.  
  27. /*
  28.  * Dynamic IO functions - let the compiler
  29.  * optimize the expressions
  30.  */
  31. extern __inline__ void __outb (unsigned int value, unsigned int port)
  32. {
  33.     unsigned long temp;
  34.     __asm__ __volatile__(
  35.     "tst    %2, #0x80000000\n\t"
  36.     "mov    %0, %4\n\t"
  37.     "addeq    %0, %0, %3\n\t"
  38.     "strb    %1, [%0, %2, lsl #2]    @ outb"
  39.     : "=&r" (temp)
  40.     : "r" (value), "r" (port), "Ir" (PCIO_BASE - IO_BASE), "Ir" (IO_BASE)
  41.     : "cc");
  42. }
  43.  
  44. extern __inline__ void __outw (unsigned int value, unsigned int port)
  45. {
  46.     unsigned long temp;
  47.     __asm__ __volatile__(
  48.     "tst    %2, #0x80000000\n\t"
  49.     "mov    %0, %4\n\t"
  50.     "addeq    %0, %0, %3\n\t"
  51.     "str    %1, [%0, %2, lsl #2]    @ outw"
  52.     : "=&r" (temp)
  53.     : "r" (value|value<<16), "r" (port), "Ir" (PCIO_BASE - IO_BASE), "Ir" (IO_BASE)
  54.     : "cc");
  55. }
  56.  
  57. extern __inline__ void __outl (unsigned int value, unsigned int port)
  58. {
  59.     unsigned long temp;
  60.     __asm__ __volatile__(
  61.     "tst    %2, #0x80000000\n\t"
  62.     "mov    %0, %4\n\t"
  63.     "addeq    %0, %0, %3\n\t"
  64.     "str    %1, [%0, %2, lsl #2]    @ outl"
  65.     : "=&r" (temp)
  66.     : "r" (value), "r" (port), "Ir" (PCIO_BASE - IO_BASE), "Ir" (IO_BASE)
  67.     : "cc");
  68. }
  69.  
  70. #define DECLARE_DYN_IN(sz,fnsuffix,instr)                    \
  71. extern __inline__ unsigned sz __in##fnsuffix (unsigned int port)        \
  72. {                                        \
  73.     unsigned long temp, value;                        \
  74.     __asm__ __volatile__(                            \
  75.     "tst    %2, #0x80000000\n\t"                        \
  76.     "mov    %0, %4\n\t"                            \
  77.     "addeq    %0, %0, %3\n\t"                            \
  78.     "ldr" ##instr## "    %1, [%0, %2, lsl #2]    @ in"###fnsuffix    \
  79.     : "=&r" (temp), "=r" (value)                        \
  80.     : "r" (port), "Ir" (PCIO_BASE - IO_BASE), "Ir" (IO_BASE)        \
  81.     : "cc");                                \
  82.     return (unsigned sz)value;                        \
  83. }
  84.  
  85. extern __inline__ unsigned int __ioaddr (unsigned int port)            \
  86. {                                        \
  87.     if (__PORT_PCIO(port))                            \
  88.         return (unsigned int)(PCIO_BASE + (port << 2));            \
  89.     else                                    \
  90.         return (unsigned int)(IO_BASE + (port << 2));            \
  91. }
  92.  
  93. #define DECLARE_IO(sz,fnsuffix,instr)    \
  94.     DECLARE_DYN_IN(sz,fnsuffix,instr)
  95.  
  96. DECLARE_IO(char,b,"b")
  97. DECLARE_IO(short,w,"")
  98. DECLARE_IO(long,l,"")
  99.  
  100. #undef DECLARE_IO
  101. #undef DECLARE_DYN_IN
  102.  
  103. /*
  104.  * Constant address IO functions
  105.  *
  106.  * These have to be macros for the 'J' constraint to work -
  107.  * +/-4096 immediate operand.
  108.  */
  109. #define __outbc(value,port)                            \
  110. ({                                        \
  111.     if (__PORT_PCIO((port)))                        \
  112.         __asm__ __volatile__(                        \
  113.         "strb    %0, [%1, %2]    @ outbc"                \
  114.         : : "r" (value), "r" (PCIO_BASE), "Jr" ((port) << 2));        \
  115.     else                                    \
  116.         __asm__ __volatile__(                        \
  117.         "strb    %0, [%1, %2]    @ outbc"                \
  118.         : : "r" (value), "r" (IO_BASE), "r" ((port) << 2));        \
  119. })
  120.  
  121. #define __inbc(port)                                \
  122. ({                                        \
  123.     unsigned char result;                            \
  124.     if (__PORT_PCIO((port)))                        \
  125.         __asm__ __volatile__(                        \
  126.         "ldrb    %0, [%1, %2]    @ inbc"                    \
  127.         : "=r" (result) : "r" (PCIO_BASE), "Jr" ((port) << 2));        \
  128.     else                                    \
  129.         __asm__ __volatile__(                        \
  130.         "ldrb    %0, [%1, %2]    @ inbc"                    \
  131.         : "=r" (result) : "r" (IO_BASE), "r" ((port) << 2));        \
  132.     result;                                    \
  133. })
  134.  
  135. #define __outwc(value,port)                            \
  136. ({                                        \
  137.     unsigned long v = value;                        \
  138.     if (__PORT_PCIO((port)))                        \
  139.         __asm__ __volatile__(                        \
  140.         "str    %0, [%1, %2]    @ outwc"                \
  141.         : : "r" (v|v<<16), "r" (PCIO_BASE), "Jr" ((port) << 2));    \
  142.     else                                    \
  143.         __asm__ __volatile__(                        \
  144.         "str    %0, [%1, %2]    @ outwc"                \
  145.         : : "r" (v|v<<16), "r" (IO_BASE), "r" ((port) << 2));        \
  146. })
  147.  
  148. #define __inwc(port)                                \
  149. ({                                        \
  150.     unsigned short result;                            \
  151.     if (__PORT_PCIO((port)))                        \
  152.         __asm__ __volatile__(                        \
  153.         "ldr    %0, [%1, %2]    @ inwc"                    \
  154.         : "=r" (result) : "r" (PCIO_BASE), "Jr" ((port) << 2));        \
  155.     else                                    \
  156.         __asm__ __volatile__(                        \
  157.         "ldr    %0, [%1, %2]    @ inwc"                    \
  158.         : "=r" (result) : "r" (IO_BASE), "r" ((port) << 2));        \
  159.     result & 0xffff;                            \
  160. })
  161.  
  162. #define __outlc(value,port)                             \
  163. ({                                        \
  164.     unsigned long v = value;                        \
  165.     if (__PORT_PCIO((port)))                        \
  166.         __asm__ __volatile__(                        \
  167.         "str    %0, [%1, %2]    @ outlc"                \
  168.         : : "r" (v), "r" (PCIO_BASE), "Jr" ((port) << 2));        \
  169.     else                                    \
  170.         __asm__ __volatile__(                        \
  171.         "str    %0, [%1, %2]    @ outlc"                \
  172.         : : "r" (v), "r" (IO_BASE), "r" ((port) << 2));            \
  173. })
  174.  
  175. #define __inlc(port)                                \
  176. ({                                        \
  177.     unsigned long result;                            \
  178.     if (__PORT_PCIO((port)))                        \
  179.         __asm__ __volatile__(                        \
  180.         "ldr    %0, [%1, %2]    @ inlc"                    \
  181.         : "=r" (result) : "r" (PCIO_BASE), "Jr" ((port) << 2));        \
  182.     else                                    \
  183.         __asm__ __volatile__(                        \
  184.         "ldr    %0, [%1, %2]    @ inlc"                    \
  185.         : "=r" (result) : "r" (IO_BASE), "r" ((port) << 2));        \
  186.     result;                                    \
  187. })
  188.  
  189. #define __ioaddrc(port)                                \
  190. ({                                        \
  191.     unsigned long addr;                            \
  192.     if (__PORT_PCIO((port)))                        \
  193.         addr = PCIO_BASE + ((port) << 2);                \
  194.     else                                    \
  195.         addr = IO_BASE + ((port) << 2);                    \
  196.     addr;                                    \
  197. })
  198.  
  199. /*
  200.  * Translated address IO functions
  201.  *
  202.  * IO address has already been translated to a virtual address
  203.  */
  204. #define outb_t(v,p)                                \
  205.     (*(volatile unsigned char *)(p) = (v))
  206.  
  207. #define inb_t(p)                                \
  208.     (*(volatile unsigned char *)(p))
  209.  
  210. #define outl_t(v,p)                                \
  211.     (*(volatile unsigned long *)(p) = (v))
  212.  
  213. #define inl_t(p)                                \
  214.     (*(volatile unsigned long *)(p))
  215.  
  216. #endif
  217.